﻿using AutoMapper;
using ManagementApi.Models;
using ManagementApi.Models.System;
using ManagementApi.Mvc;
using ManagementApi.Mvc.ApplicationContexts;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Modules.System.EarlyWarning;

namespace ManagementApi.Controllers.AdminPannel
{
    /// <summary>
    /// 预警记录表
    /// </summary>
    [Route("/api/v1/sysuser/sysEarlyWarning")]
    [ApiController]
    [Authorize(Roles = "SysUser")]
    public class SysEarlyWarningController : ControllerBase
    {
        private readonly ManagementApplicationContext applicationContext;
        private readonly IMapper mapper;
        private readonly SysEarlyWarningService sysEarlyWarningService;

        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="applicationContext">上下文</param>
        /// <param name="mapper">mapper映射</param>
        /// <param name="sysEarlyWarningService">主业务service</param>
        public SysEarlyWarningController(ManagementApplicationContext applicationContext, IMapper mapper, SysEarlyWarningService sysEarlyWarningService)
        {
            this.applicationContext = applicationContext;
            this.mapper = mapper;
            this.sysEarlyWarningService = sysEarlyWarningService;
        }

        /***进入模版管理可以修改模版***/

        /// <summary>
        /// 获取预警记录表列表(分页)
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <param name="pageNum">页码</param>
        /// <param name="pageSize">每页数量</param>
        /// <returns></returns>
        [HttpGet("page")]
        public ApiResult<PageDto<SysEarlyWarningDto>> GetSysEarlyWarnings([FromQuery] SysEarlyWarningQuery query, int pageNum = 1, int pageSize = 20)
        {
            var data = sysEarlyWarningService.GetSysEarlyWarnings(query, pageNum, pageSize);
            var dtos = data.AsPageDto(source => { return source.AsProjectWarningDto(); });
            return ApiResult<PageDto<SysEarlyWarningDto>>.Success(dtos);
        }
    }
}